﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Main_Inventory_PurchaseReciveDetails : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string poid = "";
    string tranrefernceid = "";
    string supplier = "";
    string taxgroup = "";
    string trnid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["poid"] != null && Request.QueryString["transferedid"] != null && Request.QueryString["supplier"] != null && Request.QueryString["taxgroup"]!=null && Request.QueryString["trnid"]!=null)
        {
            poid = Request.QueryString["poid"].ToString();
            tranrefernceid = Request.QueryString["transferedid"].ToString();
            supplier = Request.QueryString["supplier"].ToString();
            taxgroup = Request.QueryString["taxgroup"].ToString();
            trnid = Request.QueryString["trnid"].ToString();
        }
        if (!IsPostBack)
        {
            bindmaindetails(poid,tranrefernceid,supplier,taxgroup);
        }
    }
    private void bindmaindetails(string poid, string tranrefernceid, string supplier, string taxgroup)
    {
       SqlParameter[] par={
                            new SqlParameter("@poid",poid),
                            new SqlParameter("@tranrefernceid",tranrefernceid)
                          };
       DataTable dtmain = DU.getdatausingprocedure("usp_ivr_get_IVRTRANMAIN", par);
      
       if (dtmain.Rows.Count > 0)
       {

           lblPONumber.Text = dtmain.Rows[0]["TFOID"].ToString();
           lblSupplier.Text = supplier;
           lblvouno.Text = dtmain.Rows[0]["trnnum"].ToString();
           lblinvno.Text = dtmain.Rows[0]["invoiceno"].ToString();
           lbldate.Text = Convert.ToString(Convert.ToDateTime(dtmain.Rows[0]["trndate"].ToString()).ToShortDateString());
           lbltaxgroup.Text = taxgroup;
           lblbilref.Text = dtmain.Rows[0]["refnum"].ToString();
           string modeofpay = "";
           if (dtmain.Rows[0]["modeofpay"].ToString() == "1")
           {
               modeofpay = "Cash";
           }
           else
           {
               modeofpay = "Credit";
           }
           lblmodeofpay.Text = modeofpay;

           SqlParameter[] parrr = { 
                                   new SqlParameter("trnid",trnid)         // data from these table ivr_tran_item, ivr_item, ivr_uom
                                  };
           DataTable dtgetitem = DU.getdatausingprocedure("usp_get_all_ivr_tran_item_ivr_item_ivr_uom", parrr);
           if (dtgetitem.Rows.Count > 0)
           {
               lblitems.Text = dtgetitem.Rows[0]["itmdesc"].ToString();
               lblunit.Text = dtgetitem.Rows[0]["uomsymbol"].ToString();
               lblrecivedqty.Text = dtgetitem.Rows[0]["itmqty"].ToString();
               lblrate.Text = dtgetitem.Rows[0]["rate"].ToString();
               lblgrossamt.Text = dtgetitem.Rows[0]["netamt"].ToString();
               lbltax.Text = dtgetitem.Rows[0]["taxper"].ToString();
               lbltaxamt.Text = dtgetitem.Rows[0]["taxamt"].ToString();
               lblamtpayble.Text = dtgetitem.Rows[0]["itmamt"].ToString();
               if (dtgetitem.Rows[0]["itmamt_lid"].ToString() != string.Empty)
               {
                   DataTable dtleder = DU.getdata("select lname from acc_ledmast where plid=" + dtgetitem.Rows[0]["itmamt_lid"].ToString());
                   if (dtleder.Rows.Count > 0)
                   {
                       if (dtleder.Rows[0]["lname"].ToString() != string.Empty)
                       {
                           lblpurchaseledger.Text = dtleder.Rows[0]["lname"].ToString();
                       }
                   }
               }
               if (dtgetitem.Rows[0]["taxamt_lid"].ToString() != string.Empty)
               {
                   DataTable dtledertax = DU.getdata("select lname from acc_ledmast where plid=" + dtgetitem.Rows[0]["taxamt_lid"].ToString());
                   if (dtledertax.Rows.Count > 0)
                   {
                       if (dtledertax.Rows[0]["lname"].ToString() != string.Empty)
                       {
                           lbltaxledger.Text = dtledertax.Rows[0]["lname"].ToString();
                       }
                   }
               }
               lbltotalitemqty.Text = dtgetitem.Rows[0]["itmqty"].ToString();
           }
           SqlParameter[] prra = {
                                  new SqlParameter("trnid",trnid)
                                 };
           DataTable dttotalamount = DU.getdatausingprocedure("usp_ivr_get_ivr_tran_total_by_trnid", prra);
           if (dttotalamount.Rows.Count > 0)
           {
               lbltotalgrossamt.Text = dttotalamount.Rows[0]["itemtotal"].ToString();
               lbltaxableamt.Text = dttotalamount.Rows[0]["taxableamt"].ToString();
               lblvatcst.Text = dttotalamount.Rows[0]["taxamt"].ToString();
               lblposttaxtotal.Text = dttotalamount.Rows[0]["trntotal"].ToString();
               lblroundoffamt.Text = dttotalamount.Rows[0]["rndoffamt"].ToString();
               lblgrandtotal.Text = dttotalamount.Rows[0]["trntotal"].ToString();
           }
           SqlParameter[] prrrrr = {
                                  new SqlParameter("trnid",trnid)
                                 };
           DataTable dtother = DU.getdatausingprocedure("usp_ivr_get_purchaseDetails_OtherDetails_by_trnid", prrrrr);
           if (dtother.Rows.Count > 0)
           {
               lblmodeofdelivery.Text = dtother.Rows[0]["modeofdelivery"].ToString();
               lbldeliverydate.Text = Convert.ToString(Convert.ToDateTime(dtother.Rows[0]["deliverydate"].ToString()).ToShortDateString());
               lbldocno.Text = dtother.Rows[0]["documentnum"].ToString();
               lbltransportname.Text = dtother.Rows[0]["transportname"].ToString();
               lblvehicleno.Text = dtother.Rows[0]["vehiclenum"].ToString();
               lblpreparedby.Text = dtother.Rows[0]["preparedby"].ToString();
               lblcheckedby.Text = dtother.Rows[0]["checkedby"].ToString();
               lblauthorizedby.Text = dtother.Rows[0]["authrsdsignat"].ToString();
               lblnarration.Text = dtother.Rows[0]["narration"].ToString();
               lblremarks.Text = dtother.Rows[0]["remarks"].ToString();
           }
       }
    }
}